﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pub;

namespace LZQXT.Test.Forms.DB
{
    public partial class FDBLogin : Form
    {
        public FDBLogin()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Program.fdb_tree.ado1.S_Con = "Data Source=" + cboxServer.Text
                + ";Initial Catalog=" + cboxDataBase.Text
                + ";Persist Security Info=True;User ID=" + tboxUser.Text
                + ";Password=" + tboxPass.Text;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void FDBLogin_Load(object sender, EventArgs e)
        {
            Program.fdbinit.db_init();

            DataSet ds1 = Program.fdbinit.sel1("SELECT DISTINCT([Server]) AS C1 FROM T_DBCon");
            if (!CDB.dsIsNull(ds1))
            {
                cboxServer.Items.Clear();
                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    cboxServer.Items.Add(ds1.Tables[0].Rows[i][0].ToString());
                }
            }

            DataSet ds2 = Program.fdbinit.sel1("SELECT DISTINCT([DataBase]) AS C1 FROM T_DBCon");
            if (!CDB.dsIsNull(ds2))
            {
                cboxDataBase.Items.Clear();
                for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                {
                    cboxDataBase.Items.Add(ds2.Tables[0].Rows[i][0].ToString());
                }
            }
        }

        private void FDBLogin_Activated(object sender, EventArgs e)
        {

        }

        private void cboxServer_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet ds1 = Program.fdbinit.sel1("SELECT * FROM T_DBCon WHERE [Server]='" + cboxServer.Text + "'");
            if (!CDB.dsIsNull(ds1))
            {
                tboxUser.Text = ds1.Tables[0].Rows[0]["User"].ToString();
                tboxPass.Text = ds1.Tables[0].Rows[0]["Pass"].ToString();
            }
        }
    }
}
